<?php
!defined('P_W') && exit('Forbidden');
$baseUrl = "$admin_file?adminjob=mode&admintype=house_hire";

InitGP(array('action'));
if (empty($action)) {
	House::LoadClass('houseurl', 'utility', false);
	InitGP(array('subject', 'username', 'type', 'user', 'top_urgent'), 'GP');
	InitGP(array('platetype', 'areatype', 'state', 'page'), 'GP', 2);
	$userService = L::loadClass('UserService', 'user');
	$user && $uid = $userService->getUserIdByUserName($user);
	(!is_numeric($page) || $page < 1) && $page=1;
	$perpage = 20;
	$hireService = House::LoadService('SecondHireService');//扩展参数	
	$areas = $hireService->getFieldsByType('area');//所有板块
	$plates = $hireService->getPlateByAreaId($areatype);	
	$top_urgent != 'none' ? ($top_urgent && $expand[$top_urgent] = 1) : $expand['istop'] = $expand['isurgent']= 0 ;//扩展参数
	$plate && $expand['plate'] = $plate;
	$index = array('areatype' => $areatype,'platetype'=>$platetype);//索引参数
	$user && $expand['uid'] = $uid;
	$state && $expand['state'] = $state;
	$keywords = array($subject);//查询并返回结果
	list($total,$result) = $hireService->getDetailList($index, 'DESC', 'posttime', $keywords, $page, $perpage, $expand);
	$url = $baseUrl . '&subject=' . $subject . '&areatype=' . $areatype . '&platetype=' . $platetype . '&user=' . $user . '&type=' . $type . '&state=' . $state;
	$returnurl = $url . '&page=' . $page;
	$pages = numofpage($total, $page, ceil($total/$perpage), $url . '&');
	include PrintMode('hire.run');
} elseif($action == 'getplate'){
	$hireService = House::LoadService('SecondHireService');
	S::gp(array('areatype'),'GP',2);
	$plates = $hireService->getPlateByAreaId($areatype);//所有板块
	echo pwJsonEncode($plates);
	ajax_footer();
}elseif ($action == 'delete') {
	InitGP(array('returnurl', 'houseids', 'from'));
	if (empty($houseids)) {
		adminmsg('operate_error');
	}
	$secondHire = House::LoadService('SecondHireService');
	$secondHire->delete($houseids);
	adminmsg('operate_success', $returnurl);
}